<?php

class CashAdvanceItemsForm extends Zend_Form
{
    public function __construct($options=array())
    {
        parent::__construct($options);

        // set form name and POST
        $this->setName('cash_advance_items');
        $this->setMethod('post');
        $this->setEnctype('multipart/form-data');

        // create basic field decorators
        $basicDecorators = array(
            'ViewHelper',
            array('Errors', array('placement'=>'prepend')),
            array('Label', array('placement'=>'prepend')),
            array( array('outerDiv'=>'HtmlTag'), array('tag'=>'div', 'style'=>'margin-top:5px')),
        );

        $desc1 = new Zend_Form_Element_Text( "desc1", array('size'=>40, 'required'=>true) );
		$desc1->setDecorators($basicDecorators);
        $amt1 = new Zend_Form_Element_Text( "amt1", array('size'=>10, 'required'=>true) );
        $this->addElements( array($desc1, $amt1) );
		$amt1->setDecorators($basicDecorators);
        
        $desc2 = new Zend_Form_Element_Text( "desc2", array('size'=>40, 'required'=>true) );
		$desc2->setDecorators($basicDecorators);
        $amt2 = new Zend_Form_Element_Text( "amt2", array('size'=>10, 'required'=>true) );
		$amt2->setDecorators($basicDecorators);
        $this->addElements( array($desc2, $amt2) );

        $desc3 = new Zend_Form_Element_Text( "desc3", array('size'=>40, 'required'=>true) );
		$desc3->setDecorators($basicDecorators);
        $amt3 = new Zend_Form_Element_Text( "amt3", array('size'=>10, 'required'=>true) );
		$amt3->setDecorators($basicDecorators);
        $this->addElements( array($desc3, $amt3) );

        $desc4 = new Zend_Form_Element_Text( "desc4", array('size'=>40, 'required'=>true) );
		$desc4->setDecorators($basicDecorators);
        $amt4 = new Zend_Form_Element_Text( "amt4", array('size'=>10, 'required'=>true) );
		$amt4->setDecorators($basicDecorators);
        $this->addElements( array($desc4, $amt4) );

        $desc5 = new Zend_Form_Element_Text( "desc5", array('size'=>40, 'required'=>true) );
		$desc5->setDecorators($basicDecorators);
        $amt5 = new Zend_Form_Element_Text( "amt5", array('size'=>10, 'required'=>true) );
		$amt5->setDecorators($basicDecorators);
        $this->addElements( array($desc5, $amt5) );

        $desc6 = new Zend_Form_Element_Text( "desc6", array('size'=>40, 'required'=>true) );
		$desc6->setDecorators($basicDecorators);
        $amt6 = new Zend_Form_Element_Text( "amt6", array('size'=>10, 'required'=>true) );
		$amt6->setDecorators($basicDecorators);
        $this->addElements( array($desc6, $amt6) );

        $desc7 = new Zend_Form_Element_Text( "desc7", array('size'=>40, 'required'=>true) );
		$desc7->setDecorators($basicDecorators);
        $amt7 = new Zend_Form_Element_Text( "amt7", array('size'=>10, 'required'=>true) );
		$amt7->setDecorators($basicDecorators);
        $this->addElements( array($desc7, $amt7) );

        $desc8 = new Zend_Form_Element_Text( "desc8", array('size'=>40, 'required'=>true) );
		$desc8->setDecorators($basicDecorators);
        $amt8 = new Zend_Form_Element_Text( "amt8", array('size'=>10, 'required'=>true) );
		$amt8->setDecorators($basicDecorators);
        $this->addElements( array($desc8, $amt8) );

        $desc9 = new Zend_Form_Element_Text( "desc9", array('size'=>40, 'required'=>true) );
		$desc9->setDecorators($basicDecorators);
        $amt9 = new Zend_Form_Element_Text( "amt9", array('size'=>10, 'required'=>true) );
		$amt9->setDecorators($basicDecorators);
        $this->addElements( array($desc9, $amt9) );

        $desc10 = new Zend_Form_Element_Text( "desc10", array('size'=>40, 'required'=>true) );
		$desc10->setDecorators($basicDecorators);
        $amt10 = new Zend_Form_Element_Text( "amt10", array('size'=>10, 'required'=>true) );
		$amt10->setDecorators($basicDecorators);
        $this->addElements( array($desc10, $amt10) );

        // form's submit button
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Submit');

        $this->addElements(array($submit));

    }

    // dirt-simple template engine.
    public function render_with_template( $template_name )
    {
        $template_file_path = APP_DIR."/views/templates/$template_name";
        $template_contents = file_get_contents( $template_file_path );

        // str_replace() keywords, adding errors where needed
        $form_elements = $this->getElements();

		$template_contents = str_replace( "{ACTION}", $this->getAction(), $template_contents );
        $template_contents = str_replace( "{CA_DESC1}", $form_elements['desc1'], $template_contents );
        $template_contents = str_replace( "{CA_AMT1}", $form_elements['amt1'], $template_contents );
        $template_contents = str_replace( "{CA_DESC2}", $form_elements['desc2'], $template_contents );
        $template_contents = str_replace( "{CA_AMT2}", $form_elements['amt2'], $template_contents );
        $template_contents = str_replace( "{CA_DESC3}", $form_elements['desc3'], $template_contents );
        $template_contents = str_replace( "{CA_AMT3}", $form_elements['amt3'], $template_contents );
        $template_contents = str_replace( "{CA_DESC4}", $form_elements['desc4'], $template_contents );
        $template_contents = str_replace( "{CA_AMT4}", $form_elements['amt4'], $template_contents );
        $template_contents = str_replace( "{CA_DESC5}", $form_elements['desc5'], $template_contents );
        $template_contents = str_replace( "{CA_AMT5}", $form_elements['amt5'], $template_contents );
        $template_contents = str_replace( "{CA_DESC6}", $form_elements['desc6'], $template_contents );
        $template_contents = str_replace( "{CA_AMT6}", $form_elements['amt6'], $template_contents );
        $template_contents = str_replace( "{CA_DESC7}", $form_elements['desc7'], $template_contents );
        $template_contents = str_replace( "{CA_AMT7}", $form_elements['amt7'], $template_contents );
        $template_contents = str_replace( "{CA_DESC8}", $form_elements['desc8'], $template_contents );
        $template_contents = str_replace( "{CA_AMT8}", $form_elements['amt8'], $template_contents );
        $template_contents = str_replace( "{CA_DESC9}", $form_elements['desc9'], $template_contents );
        $template_contents = str_replace( "{CA_AMT9}", $form_elements['amt9'], $template_contents );
        $template_contents = str_replace( "{CA_DESC10}", $form_elements['desc10'], $template_contents );
        $template_contents = str_replace( "{CA_AMT10}", $form_elements['amt10'], $template_contents );

        $template_contents = str_replace( "{SUBMIT_BUTTON}", $this->submit, $template_contents );

        echo $template_contents;
    }
}

?>
